package cn.mothin.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.mothin.entity.MenuItemConfig;
import cn.mothin.frame.core.base.BaseDao;

@Repository("7cb7e185-45dc-4960-8247-6c5d953f3cf4")
public class MenuItemConfigDao extends BaseDao<MenuItemConfig> {

    public List<MenuItemConfig> findByMenuId(String menuId) {
        String sql = "SELECT * FROM menu_item_config WHERE menuConfigId=? ORDER BY ordinal";
        return query(sql, menuId);
    }

    // 2013-05-24
    public List<MenuItemConfig> findByMenuId(String menuId, String targetId) {
        String sql = "SELECT * FROM menu_item_config WHERE menuConfigId=? AND functionModuleId IN (SELECT moduleItemId FROM role_module_permission WHERE targetId = ?) ORDER BY ordinal";
        return query(sql, menuId, targetId);
    }

    public List<MenuItemConfig> findLoginUserSuper(String menuId) {
        String sql = "SELECT * FROM menu_item_config WHERE menuConfigId=? ORDER BY ordinal";
        return query(sql, menuId);
    }

    public List<MenuItemConfig> findLoginUser(String menuId, String userId) {
        String sql = "SELECT * FROM menu_item_config WHERE menuConfigId=? AND functionModuleId IN (SELECT moduleItemId FROM role_module_permission WHERE targetId IN (SELECT systemRoleId FROM system_user_role WHERE systemUserId = ?)) ORDER BY ordinal";
        return query(sql, menuId, userId);
    }
}
